# -*- coding: utf-8 -*-
import scrapy

from mansite.items import MansiteItem


class SoneSpider(scrapy.Spider):
    name = 'sone'
    allowed_domains = ['m.nanrenvip.cc']
    start_urls = ['http://m.nanrenvip.cc/s1s1s1/']

    def parse(self, response):
        # 输出到日志中
        # self.log('title: %s'% response.xpath('.//*[@class="book-title"]/text()').extract())
        # self.log('desc: %s'% response.xpath('.//*[@class="book-desc"]/text()').extract())
        # self.log('image: %s'% response.xpath('.//img/@data-echo').extract())
        # self.log('duration: %s'% response.xpath('.//span/em[1]/text()').extract())
        # self.log('type: %s'% response.xpath('.//span/em[2]/text()').extract())
        # self.log('pubDate: %s'% response.xpath('.//span/em[3]/text()').extract())

        # 输出到Item
        manItem = MansiteItem()
        manItem['title'] = response.xpath('.//*[@class="book-title"]/text()').extract()
        manItem['desc'] = response.xpath('.//*[@class="book-desc"]/text()').extract()
        manItem['image'] = response.xpath('.//img/@data-echo').extract()
        manItem['duration'] = response.xpath('.//span/em[1]/text()').extract()
        manItem['type'] = response.xpath('.//span/em[2]/text()').extract()
        manItem['pubDate'] = response.xpath('.//span/em[3]/text()').extract()

        return manItem
